#include <iostream>
#include <string>
#include <vector>

void printMenu(const std::string& path, const std::vector<std::string>& items) {
   int index = 1;
   for (const std::string& item : items) {
       std::cout << "[" << index << "] " << item << std::endl;
       index++;
   }

   std::cout << "[0] 返回上一级" << std::endl;
   std::cout << "请选择：";

   int choice;
   std::cin >> choice;

   if (choice == 0) {
       return;
   } else if (choice > 0 && choice <= items.size()) {
       std::string selectedItem = items[choice - 1];
       if (path.empty()) {
           printMenu("/", {selectedItem});
       } else {
           printMenu(path + "/" + selectedItem, {});
       }
   } else {
       std::cout << "无效的选择，请重新输入" << std::endl;
       printMenu(path, items);
   }
}

void printTree(const std::string& path, const std::vector<std::string>& items) {
   for (const std::string& item : items) {
       std::cout << path + "/" + item << std::endl;
   }
}

void navigateTree(const std::string& path, const std::vector<std::string>& items) {
   if (items.empty()) {
       printTree(path, items);
       return;
   }
   printMenu(path, items);
}

int main() {
   std::vector<std::string> items = {"file1", "file2", "file3", "dir1", "dir2"};
   navigateTree("", items);

   return 0;
}